<%-- 
    Document   : formAjoutCreneau2
    Created on : 29 mars 2013, 14:13:39
    Author     : ali
--%>

<%@page import="java.util.HashMap"%>
<%@page import="com.sun.corba.se.impl.encoding.CodeSetConversion.CTBConverter"%>
<%@page import="EDT.obj.Formation"%>
<%@page import="java.util.ArrayList"%>

  <%@ pageimport = "org.w3c.dom.*"%>

<%@page contentType="text/html" pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
                
        <title>Emplois du temps promo form</title>
            <link rel="stylesheet" href="Accueil.css" />
            <link rel="SHORTCUT ICON" href="./edt.jpg" />
            
               
            <script language="JavaScript">
                                
               function getNbGp(idp){
               var idpromo = idp.value;
               var nbGp = document.getElementById(idpromo).value;
                var select = document.createElement('select');
                select.setAttribute("name", "groupe");
                select.setAttribute("id", "groupe");
                var option;
                //alert(nbGp);
                var i=1;
                
                while (i<= nbGp)
                {
                    option = document.createElement('option');
                    option.setAttribute("value", i);
                    option.appendChild(document.createTextNode(i));
                    select.appendChild(option);
                    i++;
                }
                //document.getElementById('grp').removeChild("groupe");
                document.getElementById('grp').replaceChild(select, document.getElementById('groupe'));
                //document.getElementById('grp').removeChild(document.getElementById('groupe'));
                //document.getElementById('grp').appendChild(select);
                //document.getElementById("grp") = select;
                
        //document.appendChild(select);
                
               }

         </script>
    </head>
    <body>
        
     
    
         
    <section>
      
    <% 
    String form ="";
    ArrayList<Formation> formation = new ArrayList<Formation>();
    
  
        
        formation = (ArrayList<Formation> ) session.getAttribute("formation");
        form +="<form method='POST' action='/EDT/ConsultAllCrAct.do' target='section'>\n";
        form += "<div class='commentaire'>\n";
        form += "<fieldset>";
        
        
        
        form += "<legend>    Choisissez une promotion  :   </legend>";
        
        String s = request.getParameter("formation");
        form += "<input type='hidden' name='formation' value='"+s+"'/>"; 
        
        form += "<input type='hidden' name='key' value='"+session.getAttribute("key")+"'/>";
        int nbrGp = 1;
        
        form += "Promotion : <select name='promotion' onchange='getNbGp(promotion);'>";
        for (Formation f : formation)
            if (f.getNom().equals(s)){
                HashMap<Integer, Integer> hashMap = f.getLesPromos();
                for (Integer mapKey : hashMap.keySet()){
                    form += "<option value='"+mapKey+"'>"+hashMap.get(mapKey)+"/"+(hashMap.get(mapKey)+1)+"</option>";
                    
                }
                    
        form += "</select><br/><br/>";
                 
                boolean first = true;
                 for (Integer mapKey : hashMap.keySet()){
                    if(first){nbrGp = f.getNbrGpPromo().get(mapKey);first =false;}
                     form += "<input type='hidden' name='idpromoNbGp'  id='"+mapKey+"' value='"+f.getNbrGpPromo().get(mapKey)+"' />";
                    
                 }
        
               form +="<input type='hidden' name='nbrperiode' value='"+f.getPeriodes()+"'/>";
                
               
               form+="<div id='grp'>";
               
                   form +="Numero de groupe :<select name='groupe' id='groupe'>";
                for (int i = 1; i<= nbrGp;i++)
                    form += "<option value='"+i+"'>"+i+"</option>";
                form += "</select><br/><br/>";
               
                form+="</div>"; 
               
                form += "Periode :   <select name='periode'>";
                form += "<option value='all'>tout</option>";
                for (int i = 1; i<= f.getPeriodes();i++)
                    form += "<option value='"+i+"'>"+i+"</option>";
                form += "</select><br/><br/>";
                

            //out.println(form);
            
        session.removeAttribute("formation");
                       
       }
    
        form +="<input type='submit' value='valider'/><br/>";
        out.println(form);
            
    %>

    <html:errors/> 
    
    </fieldset>
    
        
    </div>
        
    
        
    </form>
        
        
        
        
    </section>
    </body>
</html>
